﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace updateMain
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            var url = "http://172.16.8.67:8090/version.xml";
            UpdateDll.Check(url, (string data, string code, string result) => {
                if ("check" == data)
                {
                    JObject o = JObject.Parse(result);
                    Console.WriteLine(o);
                    if (o["update"] != null && "true".Equals(o["update"].ToString().ToLower()))
                    {
                        JArray details = JArray.Parse(o["detail"].ToString());
                        JObject detail0 = JObject.Parse(details[0].ToString());
                        var files = "";
                        foreach (var file in detail0["files"])
                        {
                            files += file.ToString() + "\r\n";
                        }
                        textBox1.Text = files;
                    }
                    else
                    {
                        MessageBox.Show("暂无更新!");
                    }
                }
            }, "check");
        }

        private void Label1_Click(object sender, EventArgs e)
        {

        }

        private void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Button2_Click(object sender, EventArgs e)
        {
            Download down = new Download();
            down.Show();
            this.Hide();
        }
    }
}
